# 1.CRUD
a = "content"
b = "text"

# Create
a += b
print(a)

# Retrieve
print(f"find: {a.find('z')}")
try:
    print(f"index: {b.index('t')}")
except ValueError:
    pass
print(f"startswith: {a.startswith('con')}, endswith: {b.endswith('ent')}")
print(f"索引：a[3:8] = {a[3:5]}, a[0] = {a[0]}, b[-1] = {b[-1]}")

# Update
print(f"replace: {a.replace('t', 'd')}")
date_str = "2020-10-25 17:39 Sun"
tmp = date_str.split(" ")
print(f"split: {tmp}")
print(f"join: {','.join(tmp)}")

# Delete
c = " 'Hello, wind !    wow/  "
print(c.strip().strip("'/"))

# 2. 字符格式化
# %
print("hello,%s" % "world")

# 按传入参数的默认顺序
print("Today is {},{}-{}-2020".format("Sunday", 10, 25))

# 按指定参数索引
print("{2}.{1}.{3}.{0}".format(172, 168, 192, 17))

# 按关键词参数
print("{name}, {age}, {city}".format(name="wind", city="SuZhou", age=24))

# 按变量
weekday = "Sunday"
print(f"Today is {weekday}!")

# 浮点数
print("{:.4f}".format(6.525619))

# 3.读取当前第二周_第二节tmp.py并写入到新文件中第二周_第二节.py
f1 = open("第二周_第二节tmp.py", "r", encoding="utf-8")
text = f1.readlines()
f2 = open("第二周_第二节.py", "w", encoding="utf-8")
f2.writelines(text)
f1.close()
f2.close()
